package com.ruicar.afs.cloud.manage.common.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.manage.common.entity.ManageApprovalRecord;
import com.ruicar.afs.cloud.manage.common.service.ManageApprovalRecordService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description: 查询审批历史
 */
@Slf4j
@RestController
@RequestMapping("/approveHistory")
@AllArgsConstructor
public class ApproveHistoryController {

    private ManageApprovalRecordService manageApprovalRecordService;

    @ApiOperation(value = "根据合同号码、案件编号查询审批历史信息")
    @PostMapping("/findByContractNo")
    public IResponse findByContractNo(@RequestParam("contractNo") String contractNo, @RequestParam("caseNo") String caseNo) {
        List<ManageApprovalRecord> list = manageApprovalRecordService.list(Wrappers.<ManageApprovalRecord>lambdaQuery()
                .eq(ManageApprovalRecord::getContractNo, contractNo)
                .eq(ManageApprovalRecord::getCaseNo, caseNo));
        return new IResponse().setData(list);
    }

    @ApiOperation(value = "根据合同号码、案件编号查询审批历史信息")
    @PostMapping("/getApprovalRecord")
    public IResponse getApprovalRecord(@RequestParam("contractNo") String contractNo, @RequestParam("caseNo") String caseNo) {
        ManageApprovalRecord manageApprovalRecord = manageApprovalRecordService.getOne(Wrappers.<ManageApprovalRecord>lambdaQuery()
                .eq(ManageApprovalRecord::getContractNo, contractNo)
                .eq(ManageApprovalRecord::getCaseNo, caseNo)
                .orderByDesc(ManageApprovalRecord::getCreateTime),false);
        return new IResponse().setData(manageApprovalRecord);
    }
}
